package cn.topcodes.tcsf.app.mapper;

import cn.topcodes.tcsf.app.domain.entity.AppUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

/**
 * @author Unicorn
 * @date 2017/5/5
 */
public interface AppUserMapper extends Mapper<AppUser> {

    @Select("SELECT FOUND_ROWS()")
    int getFoundRows();

    @Select("select SQL_CALC_FOUND_ROWS id, created_time as createdTime, updated_time as updatedTime, " +
            "data_state as dataState, username, real_name as realName, password, " +
            "tel, email, gender, head_img_url as headImgUrl, role from t_app_user " +
            "where id in (" +
            "select app_user_id from t_app_daily_active_users where dau_date >= #{startTime} and dau_date <= #{endTime}" +
            ") limit ${(page - 1) * size}, #{size}")
    List<AppUser> findActiveUsers(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("page") int page, @Param("size") int size);
}
